#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:

    int func(int n)
    {
        int sum = 0;
        while (n != 0)
        {

            sum = sum + (n % 10) * (n % 10);
            n = n / 10;
        }
        return sum;
    }

    bool isHappy(int n) {

        int slow = n;
        int fast = func(n);

        while (slow != fast)
        {
            slow = func(slow);
            fast = func(func(fast));
        }

        if (slow == 1)
        {
            return true;
        }
        return false;

    }
};